package com.senlan.water.common.util;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;

public class DateUtil {

    /**
     * 把日期转换为当天最大时间
     * @param date  2024-12-03 00:00:00
     * @return 2024-12-03 23:59:59
     */
    public static Date convertDate(Date date){
        if (date == null){
            date = new Date();
        }
        // 将 Date 转换为 LocalDateTime
        LocalDateTime localDateTime = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();

        // 修改时、分、秒
        LocalDateTime modifiedDateTime = localDateTime.withHour(23)
                .withMinute(59)
                .withSecond(59);

        // 如果需要，将 LocalDateTime 转换回 Date
        return Date.from(modifiedDateTime.atZone(ZoneId.systemDefault()).toInstant());
    }
}
